package com.platform.study;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by apple on 17/10/20.
 */
@SpringBootApplication
@RestController
public class Application {

    @Autowired
    RedisTemplate<String, String> redisTemplate;

    @RequestMapping("/")
    public void hello(){
        String key = "redisTestKey";
        String value = "I am test value";

        ValueOperations<String, String> opsForValue = redisTemplate.opsForValue();
        //数据插入测试：
        opsForValue.set(key, value);
        String valueFromRedis = opsForValue.get(key);
        System.out.println(valueFromRedis);

        //数据删除测试：
        redisTemplate.delete(key);
        valueFromRedis = opsForValue.get(key);
        System.out.println(valueFromRedis);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}